package cn.wolfcode.service.impl;

import cn.wolfcode.domain.ZmessageBoard;
import cn.wolfcode.mapper.ZmessageBoardMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IZmessageBoardService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ZmessageBoardServiceImpl implements IZmessageBoardService {

    @Autowired
    private ZmessageBoardMapper zmessageBoardMapper;


    @Override
    public void save(ZmessageBoard zmessageBoard) {
        zmessageBoard.setZcreateTime(new Date());
        zmessageBoard.setZreplystatus(false);
        zmessageBoardMapper.insert(zmessageBoard);
    }

    @Override
    public void delete(Long id) {
        zmessageBoardMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(ZmessageBoard zmessageBoard) {
        zmessageBoardMapper.updateByPrimaryKey(zmessageBoard);
    }

    @Override
    public ZmessageBoard get(Long id) {
        return zmessageBoardMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ZmessageBoard> listAll() {
        return zmessageBoardMapper.selectAll();
    }

    @Override
    public PageInfo<ZmessageBoard> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<ZmessageBoard> zmessageBoards = zmessageBoardMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<ZmessageBoard>(zmessageBoards);
    }
    //根据id查询明细
    @Override
    public ZmessageBoard selectById(Long id) {
        return zmessageBoardMapper.selectById(id);
    }
}
